import React, { Component } from "react";
import "./openFail.scss";
import { connect } from "react-redux";
import XFButton from "../../../xfCompontent/xfButton/xfButton";
import openFail from "../../../images/imageXHF/openFail.png";
import MainLayout from "../../../component/mainLayout/mainLayout";
import yhTools from "@/tools/yh";
import { InterfaceG } from "@config/Config";
import Banner from "@/views/viewCommon/Banner";

export class OpenFail extends Component {
	constructor(props) {
		super(props);
		this.state = {
			btnText: "返回首页",
			subTitle: "",
			bannerList: []
		};
	}

	componentDidMount() {
		this.getBannerListByPageType();
	}

	componentWillUnmount() {}
	btnFn() {
		yhTools.closePage();
	}
	gotoXyPage() {}

	//获取banner
	getBannerListByPageType = () => {
		const params = {
			url: InterfaceG.getBannerListByPageType,
			params: {
				pageType: "XHD_CREDIT_RESULT_PAGE"
			},
			_alertShow: false
		};
		yhTools.request(params).then(res => {
			if (res.code === "0") {
				if (res.data && res.data.length > 0) {
					res.data.forEach(item => {
						if (item.bannerType == "XHD_CREDIT_RESULT_REJECT_PAGE") {
							this.setState({
								bannerList: item.indexServerDtos ? item.indexServerDtos : []
							});
						}
					});
				}
			}
		});
	};

	render() {
		const { btnText = "", bannerList } = this.state;
		let _pageParams = {
			header: {
				title: "开通结果"
				// goToApp: true
				// goBackPath: "xhdHome"
			},
			history: this.props.history,
			cacheLifecycles: this.props.cacheLifecycles
		};
		const btnStyle = {
			height: "1rem",
			width: "3.78rem",
			borderRadius: ".5rem"
		};
		return (
			<MainLayout pageParams={_pageParams}>
				<div className="xhd_openFail">
					<div className="openFail-box">
						<img src={openFail} />
						<h3>暂时不能提供借款服务</h3>
						<p>根据系统审核评定，您暂时不符合放款标准</p>
						<p className="p1">多在永辉超市购物，有助于提升您的信用哦</p>
					</div>
					<XFButton
						btText={btnText}
						handleBtn={this.btnFn.bind(this)}
						btnStyle={btnStyle}
					/>
					{bannerList.length > 0 && (
						<div className="xhd-open-result-banner">
							<h1>更多金融服务</h1>
							<Banner bannerList={bannerList} history={this.props.history} />
						</div>
					)}
				</div>
			</MainLayout>
		);
	}
}

function mapStateToProps(state) {
	return state;
}

function mapDispatchToProps() {
	return {};
}

const OpenFailPage = connect(mapStateToProps, mapDispatchToProps)(OpenFail);
export default OpenFailPage;
